declare global {
  interface Window {
    [key: string]: any;
  }
}
const NAMESPACE = "lottery";
export default function useGlobal() {
  if (!window[NAMESPACE]) {
    window[NAMESPACE] = {};
  }
  function setGlobal(key: string | number, value: any) {
    window[NAMESPACE][key] = value;
  }

  function getGlobal(key: string | number) {
    return window[NAMESPACE][key];
  }

  function deleteGlobal(key: string | number) {
    delete window[NAMESPACE][key];
  }

  function hasGlobal(key: string | number) {
    return key in window[NAMESPACE];
  }

  function getAllGlobal() {
    return window[NAMESPACE];
  }

  function clearGlobal() {
    window[NAMESPACE] = {};
  }

  return {
    setGlobal,
    getGlobal,
    deleteGlobal,
    hasGlobal,
    getAllGlobal,
    clearGlobal
  };
}

/*
// 使用示例：
// 页面1 设置
const { setGlobal, getGlobal, deleteGlobal } = useGlobal();
setGlobal("key1", "value1");
// 页面2 获取
getGlobal("key1");
// 页面3 删除
deleteGlobal("key1");
*/
